#include <iostream>
#include <algorithm>
#include <cstdio>
#include <array>
#include <vector>
#include <set>
#define ll long long
#define pii pair <int, int>
using namespace std;
#ifdef ONLINE_JUDGE

#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 23], *p1 = buf, *p2 = buf, ubuf[1 << 23], *u = ubuf;

#endif
int read() {
    int p = 0, flg = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') flg = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        p = p * 10 + c - '0';
        c = getchar();
    }
    return p * flg;
}
void write(ll x) {
    if (x < 0) {
        x = -x;
        putchar('-');
    }
    if (x > 9) {
        write(x / 10);
    }
    putchar(x % 10 + '0');
}
bool _stmer;

const int N = 1e5 + 5;

#define fi fisrt
#define se second

multiset <pii> isl, ksl;
array <int, N> s, h;

bool _edmer;
int main() {
    cerr << (&_stmer - &_edmer) / 1024.0 / 1024.0 << "MB\n";
#ifndef cxqghzj
    freopen("boast.in", "r", stdin);
    freopen("boast.out", "w", stdout);
#endif
    int n = read();
    for (int i = 1; i <= n; i++) {
        s[i] = read(), h[i] = read();
        isl.insert(make_pair(s[i], i));
        ksl.insert(make_pair(s[i] + h[i], i));
    }
    ll ans = 2e18;
    for (int i = 1; i <= n; i++) {
        isl.erase(make_pair(s[i], i));
        ksl.erase(make_pair(s[i] + h[i], i));
        ll now = s[i];
        vector <pii> idx;
        set <int> tp;
        idx.push_back(*isl.begin()), idx.push_back(*(++isl.begin()));
        idx.push_back(*ksl.begin()), idx.push_back(*(++ksl.begin()));
        sort(idx.begin(), idx.end());
        for (auto k : idx) tp.insert(k.se);
        while (tp.size() > 2) tp.erase(--tp.end());
        for (auto k : tp) now += s[k] + max(h[i], h[k]);
        isl.insert(make_pair(s[i], i));
        ksl.insert(make_pair(s[i] + h[i], i));
        ans = min(ans, now);
    }
    write(ans), puts("");
    return 0;
}
